package com.masterclient.app.modules.firstpager.fragments.adapters;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.masterclient.app.R;
import com.eoner.baselibrary.bean.firstpager.BrandsRecommendBean;
import com.eoner.baselibrary.utils.GlideUtil;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.masterclient.app.widget.CircleImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者：sean
 * 创建时间：2017/6/14 16:39
 * 功能说明：首页 品牌页 头部 pageradapter
 */

public class BrandHeadPagerAdapter extends PagerAdapter {
    private List<BrandsRecommendBean.DataBean.ShBrandRemBean> list;
    private Context context;

    public BrandHeadPagerAdapter(Context context, List<BrandsRecommendBean.DataBean.ShBrandRemBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_recommend_brand, null);
        ImageView ivGoods = (ImageView) view.findViewById(R.id.iv_goods);
        TextView tvShopName = (TextView) view.findViewById(R.id.tv_shop_name);
        TextView tvShopFoundTime = (TextView) view.findViewById(R.id.tv_shop_found_time);
        TextView tvShopDesc = (TextView) view.findViewById(R.id.tv_shop_desc);
        TextView tvLocation = (TextView) view.findViewById(R.id.tv_location);
        ImageView ciShopLogo = (ImageView) view.findViewById(R.id.ci_shop_logo);
        BrandsRecommendBean.DataBean.ShBrandRemBean bean = list.get(position);
        if(bean!=null){
            GlideUtil.displayImage(context,bean.getSh_image(),ivGoods);
            GlideUtil.displayCircleImage(context,bean.getSh_logo(),ciShopLogo,R.mipmap.user_head_default_icon,ScreenUtils.dp2px(60),ScreenUtils.dp2px(60));
//            App.picasso.load(bean.getSh_image()).fit().into(ivGoods);
//            App.picasso.load(bean.getSh_logo()).transform(new CircleBorderTransform(ScreenUtils.dp2px(0.5f),R.color.bg_gray)).resize(ScreenUtils.dp2px(60),ScreenUtils.dp2px(60)).into(ciShopLogo);
            tvShopName.setText(bean.getSh_name());
            tvLocation.setText(bean.getSh_province_name()+" "+bean.getSh_city_name());
            tvShopDesc.setText(bean.getSh_subname());
            tvShopFoundTime.setText(bean.getSh_create_time());
        }

        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(((View) object));
    }

    static class ViewHolder {
        @BindView(R.id.iv_goods)
        ImageView ivGoods;
        @BindView(R.id.tv_shop_name)
        TextView tvShopName;
        @BindView(R.id.tv_shop_found_time)
        TextView tvShopFoundTime;
        @BindView(R.id.tv_shop_desc)
        TextView tvShopDesc;
        @BindView(R.id.tv_location)
        TextView tvLocation;
        @BindView(R.id.ci_shop_logo)
        CircleImageView ciShopLogo;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
